<?php
namespace App\Listener;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

use App\Repository\LevelRepository;

/**
 * @Listener 
 */
class UserMoneyFullAllListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            \App\Event\User\MoneyFullEvent::class,
        ];
    }
    
    // 用户获到奖金补贴变动
    public function process($event)
    {
        // 日志
        $log = $event->log();
        
        // 判断是不是获取补贴奖金
        if($log['type'] && $log['money'] > 0)
        {
            // 收入增加
            $event->user->moneyFullAll($log['money']);
            
            // 算出税收
            $tax = LevelRepository::make($event->user->level)->fullTax($log['money']);
            
            // 扣税
            $event->user->moneyFullMake($tax, '综合服务费', 'tax');
        }
        
    }
}